package com.tbit.uqbike.webmanager.controller;

import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.pojo.ParkPointBound;
import com.tbit.uqbike.object.pojo.ParkPointBoundAbnormal;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.EquipmentMaintainService;
import com.tbit.uqbike.webmanager.util.Assert;
import com.tbit.uqbike.webmanager.util.excel.ExcelUtil;
import com.tbit.uqbike.webmanager.util.page.DPage;
import com.tbit.uqbike.webmanager.util.page.PageDomain;
import com.tbit.uqbike.webmanager.util.page.TableSupport;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author HZW
 * @ClassName RFIDInfoController
 * @Description 站点设备维护Controller层
 * @date 2021/12/16 9:42
 * @Version 1.0
 */
@RestController
@RequestMapping("/equipmentInfo")
public class EquipmentMaintainController extends BaseController {
    @Resource
    private EquipmentMaintainService equipmentMaintainService;

    /**
     * @描述 获取站点设备（rfid、道钉）图表信息
     * @参数
     * @创建人 hzw
     * @创建时间 2021/12/20
     * @修改人和其它信息
     */
    @RequestMapping("/chart")
    public JsonResult chartData(ParkPointBoundAbnormal parkPointBoundAbnormal) {
        Map<String, Object> map = equipmentMaintainService.selectAbnormalTotal(parkPointBoundAbnormal);
        return JsonResult.ok(map);
    }


    /**
     * @描述 获取站点设备（rfid、道钉）详情信息
     * @参数
     * @创建人 hzw
     * @创建时间 2021/12/16
     * @修改人和其它信息
     */
    @RequestMapping("/queryPage")
    public JsonResult queryPage(ParkPointBound parkPointBound) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNO = pageDomain.getPageNO();
        Integer rowCount = pageDomain.getRowCount();
        List<ParkPointBound> list = equipmentMaintainService.getInfo(parkPointBound);
        DPage<ParkPointBound> dPage = new DPage<>(list, pageNO, rowCount);
        List<ParkPointBound> dataList = dPage.getList();
        //dataList.forEach(ParkPointBound::dateFormat);
        return JsonResult.ok(dataList, dPage.getTotal());
    }

    /**
     * @描述 获取站点异常设备（rfid、道钉）总览数据
     * @参数
     * @创建人 hzw
     * @创建时间 2021/12/20
     * @修改人和其它信息
     */
    @RequestMapping("/aggregateData")
    public JsonResult aggregateData(ParkPointBoundAbnormal parkPointBoundAbnormal) {
        Assert.notNull(parkPointBoundAbnormal.getType(), "请选择设备类型");
        startPage();
        List<ParkPointBoundAbnormal> list = equipmentMaintainService.getAbnormalInfo(parkPointBoundAbnormal);
        return JsonResult.ok(list, (int) new PageInfo<>(list).getTotal());
    }


    /**
     * 导出详情
     * @param parkPointBound parkPointBound
     * @return Result<Object>
     */
    @PostMapping("/exportExcel")
    public Result<Object> exportExcel(ParkPointBound parkPointBound){
        List<ParkPointBound> list = equipmentMaintainService.getInfo(parkPointBound);
        ExcelUtil<ParkPointBound> excelUtil = new ExcelUtil<>(ParkPointBound.class);
        JsonResult data = excelUtil.exportExcel(list, "站点设备详情");
        return Result.success(data.getData());
    }

    /**
     * 导出站点设备总览
     * @param parkPointBoundAbnormal parkPointBoundAbnormal
     * @return Result<Object>
     */
    @PostMapping("/exportAggregate")
    public Result<Object> exportAggregate(ParkPointBoundAbnormal parkPointBoundAbnormal){
        Assert.notNull(parkPointBoundAbnormal.getType(), "请选择设备类型");
        List<ParkPointBoundAbnormal> list = equipmentMaintainService.dataFormat(equipmentMaintainService.getAbnormalInfo(parkPointBoundAbnormal));
        ExcelUtil<ParkPointBoundAbnormal> excelUtil = new ExcelUtil<>(ParkPointBoundAbnormal.class);
        JsonResult result = excelUtil.exportExcel(list, "站点设备总览");
        return Result.success(result.getData());
    }
}
